package com.ygqh.baby.service.impl;
import java.util.Date;
import java.util.List;

import  com.ygqh.baby.ao.QueryInfo;
import  com.ygqh.baby.ao.ResultSet;
import  com.ygqh.baby.po.AdminSupplierInvoice;
import  com.ygqh.baby.mapper.AdminSupplierInvoiceMapper;
import  com.ygqh.baby.service.AdminSupplierInvoiceService;

import  org.springframework.util.Assert;

import java.util.Arrays;

import  org.springframework.stereotype.Service;
import  org.springframework.beans.factory.annotation.Autowired;

import  com.ygqh.baby.po.AdminSupplierInvoiceExample;
import  com.ygqh.baby.ao.DataStatus;

@Service
public class AdminSupplierInvoiceServiceImpl implements AdminSupplierInvoiceService{
	
	@Autowired
	private AdminSupplierInvoiceMapper adminSupplierInvoiceMapper;
	
	@Override
	public List<AdminSupplierInvoice> find() {
		AdminSupplierInvoiceExample example = new AdminSupplierInvoiceExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplierInvoiceMapper.selectByExample(example);
	}

	@Override
	public int findCount() {
		AdminSupplierInvoiceExample example = new AdminSupplierInvoiceExample();
		example.createCriteria().andStatusEqualTo(DataStatus.Valid.name());
		return adminSupplierInvoiceMapper.countByExample(example);
	}

	@Override
	public AdminSupplierInvoice findById(Long id) {
		return adminSupplierInvoiceMapper.selectByPrimaryKey(id);
	}


	

	@Override
	public int save(AdminSupplierInvoice adminSupplierInvoice) {
		return adminSupplierInvoiceMapper.insertSelective(adminSupplierInvoice);
	}

	@Override
	public int update(AdminSupplierInvoice adminSupplierInvoice) {
		return adminSupplierInvoiceMapper.updateByPrimaryKeySelective(adminSupplierInvoice);
	}

	@Override
	public ResultSet<AdminSupplierInvoice> search(QueryInfo queryInfo,String q,String salesCompany) {
		List<AdminSupplierInvoice>  list =  adminSupplierInvoiceMapper.selectSuper(queryInfo, q,salesCompany);
		int count = adminSupplierInvoiceMapper.countSuper(q,salesCompany);
		ResultSet<AdminSupplierInvoice> resultSet = new ResultSet<AdminSupplierInvoice>(count,list);
		return resultSet;
	}

	@Override
	public int deleteSoft(Long[] ids) {
		Assert.notEmpty(ids);
		AdminSupplierInvoiceExample example = new AdminSupplierInvoiceExample();
		example.createCriteria().andIdIn(Arrays.asList(ids));
		AdminSupplierInvoice record = new AdminSupplierInvoice();
		record.setStatus(DataStatus.Delete);

		return adminSupplierInvoiceMapper.updateByExampleSelective(record, example);
	}
	
	@Override
	public int deleteSoft(Long id) {
		return this.deleteSoft(new Long[]{id});
	}

	@Override
	public int saveOrUpdate(AdminSupplierInvoice adminSupplierInvoice) {
		int r = 0;
		if(adminSupplierInvoice.getId() != null) {
			r = this.update(adminSupplierInvoice);
		}else {
			r = this.save(adminSupplierInvoice);
		}
		return r;
	}

	@Override
	public void saveBatchSupplierInvoice(List<AdminSupplierInvoice> adminInvoice) {
		adminSupplierInvoiceMapper.inserBatchSupplierInvoice(adminInvoice);
		
	}

}

